jQuery(function($) {

  var xhtml = $('#awplus_content td center').html().replace(/^.*?<br>(.*)$/mg, '$1');
  $('#awplus_content td center').html(xhtml);
  // fix DOM rebuild
  awPlus.ap_player_attachClickByClass();

  var members = $.cookie('ap_memberlist').split('|');
  var id = parseInt(document.location.href.match(/id=([0-9]+)$/)[1]);

  var html = '<div style="margin: 10px;"><select id="ap_memberlist">';
  var m, sel;
  for (var i = 0; i < members.length; i++) {
    m = members[i].split(':');
    sel = (m[0] == id) ? 'selected="selected"' : '';
    html += '<option value="'+m[0]+'" '+sel+'>'+m[1]+'</option>';
  }
  html += '</select></div>';

  $('#awplus_content td center').prepend(html);

  var link_style = 'style="margin: 0px 5px; padding:0.1em 1em 0.2em 0.5em; position:relative; text-decoration:none;"';
  var icon_style = 'style="left:0.2em; margin:-8px 0 0 0; position:absolute; top:50%;"';

  if (id > 0) {
    $('#ap_memberlist').before('<a href="?id='+(id-1)+'" class="ui-state-default ui-corner-all" '+link_style+'><div class="ui-icon ui-icon-seek-prev" '+icon_style+' /></a>');
  }

  if (id < members.length-1) {
    $('#ap_memberlist').after('<a href="?id='+(id+1)+'" class="ui-state-default ui-corner-all" '+link_style+'><div class="ui-icon ui-icon-seek-next" '+icon_style+' /></a>');
  }

  $('#ap_memberlist').change(function() {
    document.location = document.location.href.match(/^(.*?=)[0-9]+$/)[1] + $(this).val();
  });

});

